package com.tarena.lbs.content.controller;

import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.content.pojo.param.ArticleCategoryParam;
import com.tarena.lbs.content.pojo.query.ArticleCategoryQuery;
import com.tarena.lbs.content.pojo.vo.ArticleCategoryVO;
import com.tarena.lbs.content.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 处理文章分类 业务模块功能
 */
@Tag(name = "文章分类管理")
@RestController
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 插入分类
     * ~
     * @return
     */
    @Operation(summary = "文章分类列表查询")
    @PostMapping("/admin/content/category/list")
    public Result<List<ArticleCategoryVO>> pageList(@RequestBody ArticleCategoryQuery categoryQuery){
        List<ArticleCategoryVO> categoryList=categoryService.selectCategory(categoryQuery);
        return new Result<>(categoryList);
    }

    @PostMapping("/admin/content/category/add")
    public Result<Void> addCategory(@RequestBody ArticleCategoryParam param){
        try{
            categoryService.addCategory(param);
            return Result.success();
        }catch (Exception e){
            return null;
        }
    }
}
